﻿namespace Sai.Test.TestDataBuilders
{
	using Sai.Core.Introspection;

	public class MethodDeclarationBuilder
	{
		private string methodName = string.Empty;
		private TypeName typeName = new TypeName();
		private bool isObsolete = false;
		private ParameterCollection parameters = new ParameterCollection();
		private TypeName declaringType = new TypeName();

		public static MethodDeclarationBuilder Method()
		{
			return new MethodDeclarationBuilder();
		}

		public MethodDeclarationBuilder Named(string name)
		{
			this.methodName = name;
			return this;
		}

		public MethodDeclarationBuilder WithReturnType(TypeName type)
		{
			this.typeName = type;
			return this;
		}

		public MethodDeclarationBuilder InClass(string name)
		{
			this.declaringType = new TypeName(new FullyQualifiedName(name));
			return this;
		}

		public MethodDeclarationBuilder InClass(TypeName type)
		{
			this.declaringType = type;
			return this;
		}


		public MethodDeclarationBuilder IsObsolete()
		{
			this.isObsolete = true;
			return this;
		}

		public MethodDeclarationBuilder WithParameter(Parameter param)
		{
			this.parameters.Add(param);
			return this;
		}

		public MethodDeclarationBuilder WithParameter(string typeName)
		{
			this.parameters.Add(new Parameter(new TypeName(new FullyQualifiedName(typeName))));

			return this;
		}

		public MethodDeclaration Build()
		{
			return new MethodDeclaration(this.methodName, this.typeName, new ObsoleteMarker(this.isObsolete), this.declaringType)
			{
				Signature = new Signature(this.methodName, this.parameters)
			};
		}
	}

}
